var map= null;


 $().ready(function() {
	initialiser();
 });
 
(function($) {

function CoordMapType() {}

	CoordMapType.prototype.tileSize = new google.maps.Size(1500,1500);
	CoordMapType.prototype.maxZoom = 19;
	CoordMapType.prototype.getTile = function(coord, zoom, ownerDocument) {
		var conteneur = ownerDocument.createElement('div');
		conteneur.style.width = this.tileSize.width + 'px';
		conteneur.style.height = this.tileSize.height + 'px';
		return conteneur;
	};

	CoordMapType.prototype.name = "map perso";
	var testMapType = new CoordMapType();

initialiser = function() {

		
		var Centre = new google.maps.LatLng(43.632598, 3.865029);
		var Options = {
			zoom: 17,
			center: Centre,
			mapTypeControl: false,
			streetViewControl: false,
		};
		map = new google.maps.Map(document.getElementById("carte"),Options);

		map.mapTypes.set('perso',testMapType);
		map.setMapTypeId('perso');
		//map.setMapTypeId('satellite');

		var Limites = new google.maps.LatLngBounds(new google.maps.LatLng(43.63041784955603, 3.8578111755409736), new google.maps.LatLng(43.636232055397926, 3.8704443800011177));
		overlayprincipal = new MainOverlay(Limites, 'map/map.png', map);
		map.setZoom(16);
		map.setCenter(Centre);

		var tabMarqueurs = new Array();
	
		google.maps.event.addListener(map, 'click', function(event) {

			var marqueur=new google.maps.Marker({
				position: event.latLng,
				map: map
			});

			google.maps.event.addListener(marqueur, 'click', function(event) {
			alert("La coordonnée du marqueur est : "+event.latLng);
			});

			tabMarqueurs.push(marqueur);
		});
	
	
	}


	/* Fonctions pour l'overlay principal */
	
	function MainOverlay(limites, image, carte) {
	 	this.bounds_ = limites;
		this.image_ = image;
		this.setMap(carte);
	}

	MainOverlay.prototype = new google.maps.OverlayView();
		
	MainOverlay.prototype.draw = function() {

		var Projection = this.getProjection();
		var SOpx = Projection.fromLatLngToDivPixel(this.bounds_.getSouthWest());
		var NEpx = Projection.fromLatLngToDivPixel(this.bounds_.getNorthEast());

		var conteneur = this.div_;
		conteneur.style.left = SOpx.x + 'px';
		conteneur.style.top = NEpx.y + 'px';
		conteneur.style.width = (NEpx.x - SOpx.x) + 'px';
		conteneur.style.height = (SOpx.y - NEpx.y) + 'px';
	}

	MainOverlay.prototype.onRemove = function() {
		this.div_.parentNode.removeChild(this.div_);
		this.div_ = null;
	}	

	MainOverlay.prototype.onAdd = function() {
		var conteneur = document.createElement('div');
		conteneur.id= "mainoverlay"
		conteneur.style.border = "none";
		conteneur.style.borderWidth = "0px";
		conteneur.style.position = "absolute";
		
		var image = document.createElement("img");
		image.src = this.image_;
		image.style.width = "100%";
		image.style.height = "100%";

		conteneur.appendChild(image);
		this.div_ = conteneur;
		var paneaux = this.getPanes();
		paneaux.overlayLayer.appendChild(conteneur);
	}

})(jQuery);
